package com.twu.biblioteca;

import java.util.LinkedList;
import java.util.List;

public class Bookstore {

    private static final Bookstore instance = new Bookstore();

    private final List<Book> available;
    private final List<Book> rent;

    private Bookstore () {
        this.available = new LinkedList<Book>();
        this.rent = new LinkedList<Book>();

        this.available.add(new Book("Cool Book", "Michel Brown", "1954"));
        this.available.add(new Book("Fast Money", "Hans Mueller", "1989"));
        this.available.add(new Book("The old Story", "Peter McDonald", "2007"));
    }

    public static Bookstore getInstance() {
        return instance;
    }

    public List<Book> getAvailableBooks() {
        List<Book> tmp = new LinkedList<Book>();
        tmp.addAll(this.available);
        return tmp;
    }

    public List<Book> getRentBooks() {
        List<Book> tmp = new LinkedList<Book>();
        tmp.addAll(this.rent);
        return tmp;
    }

    public boolean checkoutBook(Book book) {
        if (available.contains(book)) {
            available.remove(book);
            rent.add(book);
            return true;
        }
        return false;
    }

    public boolean returnBook(Book book) {
        if (rent.contains(book)) {
            rent.remove(book);
            available.add(book);
            return true;
        }
        return false;
    }

    public void reset() {
        this.available.addAll(rent);
        this.rent.clear();
    }

}
